﻿using System;
using System.Security.Cryptography;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using SuppKids.Licensing.LicenseManager.Utilities.RSA;

namespace SuppKids.Licensing.LicenseManager.IoC
{
    public static class WindsorContainerExtensions
    {
        public static void RegisterComponents(this IWindsorContainer container)
        {
            container.Register(Component.For<IWindsorContainer, WindsorContainer>().Instance(container));
            container.Register(Component.For<RSACryptoTransformer>()
                .UsingFactoryMethod(() =>
                {
                    const string privateAndPublicKeys = "BwIAAACkAABSU0EyAAgAAAEAAQCJor8OmUsnowPUfyHQn+VN+rVE663z19gKjH8vs7gSCDhz87G6kgorzQQfpxLoYZpu3PQiNzrkIOmg1P3fVC04BGZzxzw32MtY1aorOk4ef5U8689vsdxBrhCNej1+EUbTQ02NKahyl6tAorzD4EigjXCYDSkRporsYzyUlv6EvV+uBSGzijmIP1RLPbCIBTe1cfmh242bzJjutY9LhxLBqnLNM1FIBfcWs1zdeVePZTV1zs39ol9W6H8fXmzZ8HF2WSkCdv1SV7YqS1LcuHGX6p4vHuimQTEWESp5n799POwNV+5TqdoRnVeWelsBa4PwVNmYTV6+nBKTgN4Ju0mTA8ly09h29b88gNdGBMmeainJ4qO81pejrCJYXaE1KoPAXjL6gJOa4vNqLE2hoLf8TEwgkWp6sn1TZk9NtULnnljvJtbz15ZdKXAHYdDoGhFD+UfA1ltKEZuKHj3SBcniQgHstrELo7B2fYKmzy2m06n820AyxGf48/+8v6kWTc6DQhCRXi7GYnueGXBtHnYbNKhWOduQsJZDFnlHJ7AqHDCUgmx6ezMzP9kwqpb6re3sQGlOnygJJoxW61y4HDgpwRTXdtVq4jtfViVbJUq/SKOzA2y/cCvIQcqZNNsgF/S9N7/lyNkLM43ojZqFexBPFoG+TVpNVZEZeZ3nGzbFtk/RzprfrCCK3+166BYiu539EjQKihiQp7Z8GVeZlhGEEbjbUDnAut2NPqjZc181DzMVLC484OizFQoBfipglGpws925MfzfAJEfhWKzbiLNwLiNmfBcW4j0uTuRw9ltVOhkK4XEnTY3Hn0Dn+Gi6NWhPY4fb6yITeSD5Saw4EQUlbgu6MwO+INuBNbAKpaK+X4jZ5eGrPoInmhSd+6+MqpMLNIxTeHhXZYbM7zvPKHbXMI+zMIG2vbdaDjpMVkZDjmVkYtjs1TI+lO4HSfuXxrW4JCTkSLsplk+LzqapUQaPlkygXRXm0JGPEZVx4PTOqYPHjvcd9SD8U/NnvlhxZ/y0v1KRH6nvuiqVcsMXqgKpejZdpuOfkzvdShJXdyuwZ6WBk2LZQY+/FUGn3zz3QKfXWQtYufimpYFMdbHNbpgQLOvelQUqHs3dHuSRJbmST3JvoNSqWxceAA9SbF+qzIdn90XEC1WykBqHoCLpoxGXHq6huHFHMXqTbQCkv/1vd2BRCnvhmOo8Vjfc7c8GSKpQPzBezKR/0TtQSz4cNZ7UwstuehkFj6oECEpinAUY/yfG12GI1qI7vqz2xA+IYoAxTm4HHk4kuPpIIYwg6+V186aup0/R4NxdibxIyG43QZbqWLX6O212c+Qev7GJApctbEHqXRLodsQEda93CG7GsJu2NKIYQR09Rs4CfZ1VBY8tdKA/phIlJDiooWAZeaSFwacLn8p+mKZGZXhlCZQTA0xAQFu1ocFqrjsj5Lv4cbM3qUOJxmnRfU4sPiMkDEQQ2HfgaTuYOsvqATKgiDjsdq0eaIyUrgq02dyzySKgwqfNvIO7eNQvjnyukYTPyc=";

                    var provider = new RSACryptoServiceProvider();

                    provider.ImportCspBlob(Convert.FromBase64String(privateAndPublicKeys));

                    return new RSACryptoTransformer(provider);
                }).LifestyleSingleton());
            container.Register(Component.For<LicenseManagementService>().ImplementedBy<LicenseManagementService>().LifestyleTransient());
        }
    }
}
